<template>
    <div class="app-container" v-loading.fullscreen.lock="fullLoading">

        <el-form :model="queryParams" ref="queryForm" size="mini" :inline="true" label-width="68px">
            <el-form-item label="学号" prop="stuNo">
                <el-input v-model="queryParams.stuNo" placeholder="请输入学号" clearable @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="学生姓名" prop="stuName">
                <el-input v-model="queryParams.stuName" placeholder="请输入学生姓名" clearable @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="奖项" prop="code">
                <el-select v-model="queryParams.code">
                    <el-option v-for="(v, i) in search_type_list" :key="i" clearable :value="v.typeCode"
                        :label="v.typeName"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label=" ">
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-table v-loading="loading" :data="table_data">
            <el-table-column label="奖项" prop="typeName" align="center" />
            <el-table-column label="学生" prop="stuName" align="center" />
            <el-table-column label="学号" prop="stuNo" align="center" />
            <el-table-column label="班级" prop="className" align="center" />
            <el-table-column label="申请时间" prop="applyTime" align="center">
                <template slot-scope="scope">
                    {{ dayjs(scope.row.applyTime).format("YYYY-MM-DD HH:mm:ss") }}
                </template>
            </el-table-column>
            <el-table-column label="申请状态" align="center">
                <template slot-scope="scope">
                    <dict-tag :options="dict.type.audius_detail_type" :value="scope.row.applyStatus" />
                </template>
            </el-table-column>
            <el-table-column label="操作" align="center">
                <template slot-scope="scope">
                    <el-button v-if="scope.row.applyStatus == 1" type="text" size="mini" icon="el-icon-view"
                        @click="auditVClick(scope.row)">审核</el-button>
                </template>
            </el-table-column>
        </el-table>
        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
            @pagination="getList" />


        <el-dialog title="申请" :visible.sync="auditV" fullscreen :append-to-body="true">
            <el-form class="detail" label-width="160px">
                <el-row>
                    <div style="display: flex;">
                        <el-col :span="12" style="margin-right: 50px;">
                            <el-form-item label="班级">
                                <el-input readonly size="mini" v-model="auditForm.className"
                                    class="auditForm-input"></el-input>
                            </el-form-item>
                            <el-form-item label="姓名">
                                <el-input readonly size="mini" v-model="auditForm.stuName"
                                    class="auditForm-input"></el-input>
                            </el-form-item>

                            <el-form-item label="政治面貌">
                                <el-input readonly size="mini" class="auditForm-input" v-model="auditForm.zzmm"></el-input>
                            </el-form-item>

                            <!-- <el-form-item v-if="!isEmpty(auditForm.youthPercent)" label="青年大学习学习率">
                                <el-input readonly size="mini" class="auditForm-input"
                                    v-model="auditForm.youthPercent"></el-input>
                            </el-form-item> -->
                            <el-form-item v-if="!isEmpty(auditForm.classtwoSure)" label="第二课堂学分认定">
                                <el-input readonly size="mini" class="auditForm-input"
                                    v-model="auditForm.classtwoSure"></el-input>
                            </el-form-item>

                            <el-form-item label="职务">
                                <el-input readonly size="mini" class="auditForm-input"
                                    v-model="auditForm.classPost"></el-input>
                            </el-form-item>
                            <el-form-item v-if="!isEmpty(auditForm.bankCard)" label="中国农业银行银行卡号">
                                <el-input readonly size="mini" class="auditForm-input"
                                    v-model="auditForm.bankCard"></el-input>
                            </el-form-item>
                            <el-form-item v-if="!isEmpty(auditForm.bankAddr)" label="开户行">
                                <el-input readonly size="mini" class="auditForm-input"
                                    v-model="auditForm.bankAddr"></el-input>
                            </el-form-item>
                            <el-form-item label="获奖情况">
                                <el-input readonly type="textarea" :maxlength="1000"
                                    :autosize="{ minRows: 10, maxRows: 10 }" class="auditForm-input"
                                    v-model="auditForm.goodHis"></el-input>
                            </el-form-item>
                            <el-form-item label="主要事迹">
                                <el-input readonly type="textarea" :maxlength="1000"
                                    :autosize="{ minRows: 10, maxRows: 10 }" class="auditForm-input"
                                    v-model="auditForm.mainHis"></el-input>
                            </el-form-item>
                            <el-form-item label="您的审核意见">
                                <el-row>
                                    <el-col :span="12">
                                        <el-select @change="changeAuditStatus" placeholder="请选择审核意见" style="width: 200px;" v-model="doForm.applyStatus" size="mini">
                                            <el-option v-for="(v, i) in status_list" :key="i" :label="v.label" :value="v.value">
                                            </el-option>
                                        </el-select>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-button @click="doAudit" type="success" size="mini">提交审核</el-button>
                                    </el-col>

                                </el-row>

                                <el-input placeholder="请输入审核意见" type="textarea" :maxlength="1000"
                                    :autosize="{ minRows: 10, maxRows: 10 }" class="auditForm-input"
                                    v-model="doForm.fdyComment"></el-input>
                            </el-form-item>
                        </el-col>


                        <el-col :span="12">
                            <div>
                                <el-row>
                                    <el-col :span="4">
                                        <span style="font-weight: bolder;">该生申请奖项:</span>
                                    </el-col>
                                    <el-col :span="8">
                                        <span style="color: red; font-weight: bolder;">
                                            {{ auditForm.typeName }}
                                        </span>
                                    </el-col>
                                    <el-col :span="6">
                                        <el-button type="primary" @click="lookNeedV = true;" size="mini">查看评优要求</el-button>
                                    </el-col>
                                </el-row>
                            </div>


                            <el-drawer :modal="false" size="50%" title="评优要求" :visible.sync="lookNeedV" direction="ltr"
                                :append-to-body="true">
                                <div class="sign">
                                    <ul>
                                        <li>
                                            申请要求:综合素质优秀。学年综合测评班级排名前30%；学习成绩优良，无不及格、补考、重修科目；体能成绩合格等
                                        </li>
                                        <li>
                                            学业之星:
                                            <ol>
                                                <li>学业成绩名列前茅。学年平均学分绩在专业排名前5%；获得校级及以上先进个人项目表彰；</li>
                                                <li>专业领域成果突出。在与专业相关的知识竞赛、技能竞赛中获奖。优先推荐发表过专业论文者。</li>
                                            </ol>
                                        </li>
                                        <li>
                                            技能之星:
                                            <ol>
                                                <li>技能或创新创业比赛成绩优异。积极参加技能训练、技能比赛或创新创业类比赛，在省部级及以上举办的技能类、创新创业类比赛中获得三等奖及以上，或在市厅级举办的技能类、创新创业类比赛中获得二等奖及以上，或在校级组织的技能类、创新创业类比赛中获得一等奖及以上；
                                                </li>
                                                <li>专业技能成绩优良。在本专业技能考核中成绩突出，学年平均学分绩在专业排名前30%；</li>
                                                <li>专业技能突出。取得与专业相关的资格、资质证书、专利（排名前五）或者在专业技能某个方面特别突出者优先考虑。</li>
                                            </ol>
                                        </li>
                                        <li>
                                            励志之星:
                                            <ol>
                                                <li>在评选学年中被认定为家庭经济困难学生，自立自强，热爱生活，吃苦耐劳，勇于拼搏，乐观向上，有突出的励志事迹，能够激励他人、影响他人，在同学中认可度高；
                                                </li>
                                                <li>在专业学习、勤工俭学、社会实践、科技创新、励志感恩、创新创业、公益服务等方面取得突出成绩；</li>
                                                <li>学业成绩优良，学年平均学分绩在专业排名前30%，获得校级及以上先进个人项目表彰。</li>
                                            </ol>
                                        </li>

                                        <li>
                                            才艺之星:
                                            <ol>
                                                <li>才艺成绩突出。在校内外各类文体赛事中（如体育、美术、音乐、舞蹈、戏剧、摄影摄像、写作、演讲、辩论等）成绩突出。
                                                </li>
                                                <li>学业成绩优良。学年平均学分绩在专业排名前30%。</li>
                                            </ol>
                                        </li>
                                        <li>
                                            服务之星:
                                            <ol>
                                                <li>积极主动为师生服务。在团委、学生会、易班、社团、协会、班级等组织中担任主要学生干部，认真履行职责，且获得过校级及以上优秀学生干部称号；
                                                </li>
                                                <li>积极参与社会服务。积极做好社会服务工作，在校级及以上大型活动中发挥重要作用，受到主办单位的嘉奖或认可，服务成效显著；</li>
                                                <li>学业成绩优良。学年平均学分绩在专业排名前30%。</li>
                                            </ol>
                                        </li>

                                        <li>
                                            <span @click="lookMore"
                                                style="text-decoration: underline;color: lightskyblue;cursor: pointer;">查看更多</span>
                                        </li>
                                    </ul>

                                </div>

                            </el-drawer>


                            <el-table :data="score_list">
                                <el-table-column label="学年" prop="stuYearName" align="center" />
                                <el-table-column label="平均学分绩" prop="stuScore" align="center" />
                                <el-table-column label="综合素质总成绩" prop="cphScore" align="center" />
                                <el-table-column label="体测成绩" prop="sportScore" align="center" />
                                <el-table-column label="平均学分绩专业排名" align="center">
                                    <template slot-scope="scope">
                                        {{ scope.row.stuMajorRank + '/' + scope.row.majorCount }}
                                    </template>
                                </el-table-column>
                                <el-table-column label="综合素质总成绩班级排名" align="center">
                                    <template slot-scope="scope">
                                        {{ scope.row.cphClassRank + '/' + scope.row.classCount }}
                                    </template>
                                </el-table-column>
                                <el-table-column label="平均学分绩专业排名百分比" align="center">
                                    <template slot-scope="scope">
                                        {{ Math.round(scope.row.stuMajorRank / scope.row.majorCount * 10000) / 100 + "%" }}
                                    </template>
                                </el-table-column>
                                <el-table-column label="学年综合素质测评班级排名百分比" align="center">
                                    <template slot-scope="scope">
                                        {{ Math.round(scope.row.cphClassRank / scope.row.classCount * 10000) / 100 + "%" }}
                                    </template>
                                </el-table-column>
                            </el-table>

                            <el-table :data="count_list">
                                <el-table-column label="学年" prop="stuYearName" align="center" />
                                <el-table-column label="课程总门数" prop="courseCount" align="center" />
                                <el-table-column label="通过门数" prop="passCount" align="center" />
                                <el-table-column label="未通过门数" prop="unpassCount" align="center" />
                            </el-table>

                            <el-row>
                                <el-col :span="12" v-for="(v, i) in course_list" :key="i">
                                    <el-table :header-row-style="{ padding: '0' }" :data="v.value"
                                        :row-style="{ height: '0' }" :cell-style="{ padding: '0' }">
                                        <el-table-column :label="v.name" align="center">
                                            <el-table-column label="课程" prop="courseName" align="center" />
                                            <el-table-column label="成绩" prop="courseScore" align="center" />
                                        </el-table-column>
                                    </el-table>
                                </el-col>
                            </el-row>

                        </el-col>
                    </div>


                </el-row>
            </el-form>

        </el-dialog>

        <el-dialog :visible.sync="lookMoreV" :append-to-body="true">
            <MoreDetail></MoreDetail>
        </el-dialog>


    </div>
</template>
<script>
import { listOwnClass } from "@/api/stuCQS/info-fill/stu_eva_task";
import { listEnableYear as listYear } from "@/api/stuCQS/basedata/year";
import { listSelect } from "@/api/stuCQS/lake/type";
import { listFdy, fdyAudit } from "@/api/stuCQS/lake/apply";

import {
    listStuScoreClassRank, listStuYearCourseScore, countStuPass, countStuIam, applyStatus
} from "@/api/stuCQS/good/audit";

import lodash from "lodash";
import { isEmpty, groupBy } from "@/api/helpFunc";
import MoreDetail from '@/views/stuCQS/lake/MoreDetail.vue';
import dayjs from "dayjs";


export default {
    name: "lakefdy",
    dicts: ['audius_detail_type'],
    components: {
        MoreDetail
    },
    data() {
        return {
            dayjs,
            applyStatus,
            search_type_list: [],

            isEmpty,

            fullLoading: false,

            loading: false,
            table_data: [],
            total: 0,
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                code: null,
                status: null,
                stuNo: "",
                stuName: ""
            },

            auditV: false,
            auditForm: {},
            material_list: [],

            score_list: [],
            myScoreV: false,
            course_list: [],
            courseParams: {
                pageNum: 1,
                pageSize: 10
            },
            courseTotal: 0,
            course_loading: false,

            count_list: [],

            iamV: false,
            iam_count: [],

            doForm: {
                id: null,
                applyStatus: null,
                fdyComment: "同意申请"
            },

            class_list: [],
            year_list: [],

            lookNeedV: false,
            lookMoreV: false,

            status_list: [
                {
                    label: "通过",
                    value: 2
                },
                {
                    label: "驳回(学生可以重新提交)",
                    value: 10
                },
                {
                    label: "拒绝(学生不可以再提交)",
                    value: 11
                }
            ]

        }
    },
    created() {
        this.listSelect();
        this.listOwnClass();
        this.listAllStuYear();
        this.getList();
    },
    methods: {
        changeAuditStatus(v){
            switch(v){
                case 2:
                    this.doForm.fdyComment = "同意申请。";
                    break;
                case 10:
                    this.doForm.fdyComment = "填写有误，请重新提交。";
                    break;
                case 11:
                    this.doForm.fdyComment = "拒绝申请。";
                    break;
                default:
                    this.doForm.fdyComment = "同意申请。";
                    break;
            }
        },
        async listSelect() {
            let res = await listSelect();
            if (res.code == 200) {
                this.search_type_list = [...res.data];
            }
        },
        lookMore() {
            this.lookMoreV = true;
            window.open('http://zhxg.gxsdxy.cn/file/jhzx2023.pdf');
        },
        async listAllStuYear() {
            let res = await listYear();
            if (res.code == 200) {
                this.year_list = [...res.rows];
            }
        },
        async listOwnClass() {
            let res = await listOwnClass();
            if (res.code == 200) {
                this.class_list = [...res.data];
            }
        },
        async getList() {
            this.loading = true;
            let res = await listFdy(this.queryParams);
            this.loading = false;
            if (res.code == 200) {
                this.table_data = [...res.rows];
                this.total = res.total;
            }
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm("queryForm");
            this.handleQuery();
        },
        async auditVClick(v) {
            this.auditForm = { ...v };
            this.auditV = true;
            this.myScoreVClick()
        },
        async countStuIam() {
            let stuNo = this.auditForm.stuNo;
            let res = await countStuIam(stuNo);
            if (res.code == 200) {
                this.iam_count = res.data;
            }
        },

        async countStuPass() {
            let stuNo = this.auditForm.stuNo;

            let res = await countStuPass(stuNo);
            if (res.code == 200) {
                this.count_list = [...res.data];
            }
        },
        async listStuYearCourseScore() {
            let stuNo = this.auditForm.stuNo;

            this.course_loading = true;
            let res = await listStuYearCourseScore(stuNo, this.courseParams);
            this.course_loading = false;

            if (res.code == 200) {

                let groupdata = groupBy([...res.rows], x => {
                    return x.termName;
                });

                let temp = [];
                for (let i in groupdata) {
                    let needAddTemp = {};
                    needAddTemp.name = i.replace(/\"/g, "");
                    needAddTemp.value = groupdata[i];
                    temp.push(needAddTemp);
                }
                this.course_list = [...temp];
                this.courseTotal = res.total;
            }
        },
        async listStuScoreClassRank() {
            let stuNo = this.auditForm.stuNo;
            let res = await listStuScoreClassRank(stuNo);
            if (res.code == 200) {
                this.score_list = lodash.cloneDeep(res.data);
            }
        },
        iamVClick() {
            this.countStuIam();
            this.countStuPass();
            this.listStuScoreClassRank();
            this.listStuYearCourseScore();
            this.iamV = true;
        },
        myScoreVClick() {
            this.countStuPass();
            this.listStuScoreClassRank();
            this.listStuYearCourseScore();
            this.myScoreV = true;
        },
        async doAudit() {
            let sdata = { ...this.doForm };
            if (isEmpty(sdata.applyStatus)) {
                this.$message.info("请选择是否通过");
                return;
            }
            if (isEmpty(sdata.fdyComment)) {
                this.$message.info("请填写审核意见");
                return;
            }
            sdata.id = parseInt(this.auditForm.id);
            this.fullLoading = true;
            let res = await fdyAudit(sdata);
            this.fullLoading = false;
            if (res.code == 200) {
                this.getList();
                this.auditForm = {};
                this.doForm = {
                    id: null,
                    applyStatus: null,
                    fdyComment: "同意申请"
                };
                this.auditV = false;
                this.$message.success(res.msg);
            }
        }
    }
}
</script>
<style lang="scss" scoped>
.addForm-input {
    width: 400px;
}

.detail {
    .el-form-item {
        margin-bottom: 0px;
    }
}

.sign {
    width: 100%;
    border: 1px solid rgb(163, 211, 255);
    font-size: small;
    margin-bottom: 10px;
    border-radius: 2px;
}
</style>